package br.ufmt.eit.cursos.filtro;

import java.io.IOException;
import java.util.Properties;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpSession;

/**
 * Servlet Filter implementation class LoginFilter
 */
public class CursosFilter implements Filter {

	private static Properties PERMISSOES_PROPERTIES = null;
	
        /**
         * Default constructor.
         */
        public CursosFilter() {
                // TODO Auto-generated constructor stub
        }

        /**
         * @see Filter#destroy()
         */
        public void destroy() {
                this.PERMISSOES_PROPERTIES = null;
        }

        

        /**
         * @see Filter#doFilter(ServletRequest, ServletResponse, FilterChain)
         */
        public void doFilter(ServletRequest request, ServletResponse response,
                        FilterChain chain) throws IOException, ServletException 
        {
                /*HttpServletRequest req = (HttpServletRequest) request;
                HttpSession session = req.getSession(true);
                String pag = req.getRequestURI();
                
               if(pag.equals("/sebrae/pages/admin/usuario/cadastrarUsuario.jsf"))
               {
            	   chain.doFilter(request, response);
               }else
               {
	                // se usuário está logado
	                Usuario usuario = ((Usuario) session.getAttribute("user"));
	                if (usuario != null) 
	                {
	                    chain.doFilter(request, response);
	                    
	                } 
	                else 
	                {
	                         setMessageError(session, "É necessário estar logado e ter permissão de acesso para visualizar esta página");
	                         ((HttpServletResponse)
	                         response).sendRedirect(session.getServletContext().getContextPath()
	                         + "/login.jsf");
	                }
               }
                UsuarioDAO dao = new UsuarioDAO();
                if(dao.estaAbertaTransacao())
                	dao.cancelarTransacao();*/
        }	

        private void setMessageError(HttpSession session, String msg){
                session.setAttribute("error", msg);
        }
        
        

        public void init(FilterConfig fConfig) throws ServletException 
        {
                
        }
}

